package cn.gov.pbc.dream.pojo.bo;

import ch.qos.logback.core.util.StringCollectionUtil;
import cn.gov.pbc.dream.common.BankFinancingProductFundInfoConst.CustomerType;

import cn.gov.pbc.dream.common.BankFinancingProductFundInfoConst;
import cn.gov.pbc.dream.util.DateTimeUtil;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@ToString
public class PCD1Bo {

    private List<BufferedReader> bufferedReaderList = new ArrayList<>();

    private List<ProductFundInfo> productFundInfoList = new ArrayList<>();

    @Data
    @ToString
    public class ProductFundInfo {

        private Date raiseDate;

        private String bankFinancingProductCode;

        private String areaCode;

        private BankFinancingProductFundInfoConst.CustomerType customerType;

        private String currencyCode;

        private BigDecimal currentPeriodPurchaseAmount;

        private BigDecimal currentPeriodPurchaseAmountRmb;

        private BigDecimal currentPeriodPurchaseShare;

        private BigDecimal currentPeriodCashedAmount;

        private BigDecimal currentPeriodCashedAmountRmb;

        private BigDecimal currentPeriodCashedShare;

        private BigDecimal endPeriodAmount;

        private BigDecimal endPeriodAmountRmb;

        private BigDecimal endPeriodShare;

        private BigDecimal netValueEndPeriod;

        private BigDecimal netValueEndPeriodRmb;

        private BigDecimal netValueAccumulativeTotalEndPeriod;

        private BigDecimal netValueAccumulativeTotalEndPeriodRmb;

        private BigDecimal openEndNonNetHighestRateOfReturn;

        private BigDecimal openEndNonNetLowestRateOfReturn;
    }

    public void assembleProductFundInfo(String data) {
        String[] values = data.split("\\|", 20);
        ProductFundInfo fundInfo = new ProductFundInfo();
        fundInfo.setRaiseDate(DateTimeUtil.strToDate(values[0], DateTimeUtil.DASH_DATE_FORMAT));
        fundInfo.setBankFinancingProductCode(values[1]);
        fundInfo.setAreaCode(values[2]);
        if (StringUtils.isNotBlank(values[3])) {
            fundInfo.setCustomerType(BankFinancingProductFundInfoConst.CustomerType.codeOf(Integer.parseInt(values[3])));
        }

        fundInfo.setCurrencyCode(values[4]);
        if(StringUtils.isNotBlank(values[5])){
            fundInfo.setCurrentPeriodPurchaseAmount(new BigDecimal(values[5]));
        }
        if(StringUtils.isNotBlank(values[6])){
            fundInfo.setCurrentPeriodPurchaseAmountRmb(new BigDecimal(values[6]));
        }
        if(StringUtils.isNotBlank(values[7])){
            fundInfo.setCurrentPeriodPurchaseShare(new BigDecimal(values[7]));
        }
        if(StringUtils.isNotBlank(values[8])){
            fundInfo.setCurrentPeriodCashedAmount(new BigDecimal(values[8]));
        }
        if(StringUtils.isNotBlank(values[9])){
            fundInfo.setCurrentPeriodCashedAmountRmb(new BigDecimal(values[9]));
        }
        if(StringUtils.isNotBlank(values[10])){
            fundInfo.setCurrentPeriodCashedShare(new BigDecimal(values[10]));
        }
        if(StringUtils.isNotBlank(values[11])){
            fundInfo.setEndPeriodAmount(new BigDecimal(values[11]));
        }
        if(StringUtils.isNotBlank(values[12])){
            fundInfo.setEndPeriodAmountRmb(new BigDecimal(values[12]));
        }
        if(StringUtils.isNotBlank(values[13])){
            fundInfo.setEndPeriodShare(new BigDecimal(values[13]));
        }
        if (StringUtils.isNotBlank(values[14])) {
            fundInfo.setNetValueEndPeriod(new BigDecimal(values[14]));
        }
        if (StringUtils.isNotBlank(values[15])) {
            fundInfo.setNetValueEndPeriodRmb(new BigDecimal(values[15]));
        }
        if (StringUtils.isNotBlank(values[16])) {
            fundInfo.setNetValueAccumulativeTotalEndPeriod(new BigDecimal(values[16]));
        }
        if (StringUtils.isNotBlank(values[17])) {
            fundInfo.setNetValueAccumulativeTotalEndPeriodRmb(new BigDecimal(values[17]));
        }
        if (StringUtils.isNotBlank(values[18])) {
            fundInfo.setOpenEndNonNetHighestRateOfReturn(new BigDecimal(values[18]));
        }
        if (StringUtils.isNotBlank(values[19])) {
            fundInfo.setOpenEndNonNetLowestRateOfReturn(new BigDecimal(values[19]));
        }
        this.productFundInfoList.add(fundInfo);
    }
}
